package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	GoodsName   string  `gorm:"type:varchar(30);"`
	GoodsCover  string  `gorm:"type:varchar(255);'"`
	GoodsPrice  float64 `gorm:"type:decimal(10,2);"`
	GoodsStatus int     `gorm:"type:tinyint(1);default:1;"`
	GoodsStock  int     `gorm:"type:int"`
	LikeCount   int     `gorm:"type:int;default:0;"`
}

func (g *Goods) Create() error {
	return DB.Debug().Create(&g).Error
}

func (g *Goods) GoodsList(status int64) (goodsList []*Goods, err error) {
	if status == 0 {
		DB.Debug().Find(&goodsList)
	} else {
		DB.Debug().Where("status=?", status).Find(&goodsList)
	}
	return
}
func (g *Goods) FindGoods(goodsId int64) error {
	return DB.Debug().Where("id=?", goodsId).Find(&g).Error
}
func (g *Goods) Update(status int) error {
	return DB.Debug().Model(&Goods{}).Update("goods_status", status).Error
}
func (g *Goods) UpdateStatus(goodsId, status int64) error {
	return DB.Debug().Model(&Goods{}).Where("id=?", goodsId).Update("goods_status", status).Error
}
